package com.tz.farmer;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tz.farmer.enums.ErrorCodeEnum;
import com.tz.farmer.mapper.*;
import com.tz.farmer.model.*;
import com.tz.farmer.service.impl.BigClassInfoImpl;
import com.tz.farmer.service.impl.GoodsSelectInfoImpl;
import com.tz.farmer.service.impl.SmallClassInfoImpl;
import com.tz.farmer.util.Configure;
import com.tz.farmer.util.HttpUtils;
import com.tz.farmer.util.ResultExM;
import com.tz.farmer.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @version V1.0
 * @description:
 * @name ScheduledTasks
 * @author: xhj
 * @date: 2021/01/16
 */
@Component
public class  ScheduledTasks {
    private static Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);

    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    BigClassInfoImpl bigClassInfoImpl;
    @Resource
    BigClassInfoMapper bigClassInfoMapper;
    @Resource
    SmallClassInfoImpl smallClassInfoImpl;
    @Resource
    GoodsSelectInfoImpl goodsSelectInfoImpl;
    @Resource
    ProductInfoMapper productInfoMapper;
    @Resource
    BusinessInfoMapper businessInfoMapper;
    @Resource
    DetectionInfoMapper detectionInfoMapper;
    @Resource
    QuickScanMapper quickScanMapper;
    @Resource
    OperateInfoMapper operateInfoMapper;
    @Resource
    TradeInfoMapper tradeInfoMapper;
    @Resource
    AuthenticationInfoMapper authenticationInfoMapper;

    /**
     * @description: 每天0点定时删除商户当日访问量
     * @name ScheduledTasks
     * @author: xhj
     * @date: 2021/7/16
     * @version V1.0
     */
    @Scheduled(cron = "0 5 0 */1 * ?")
    public void updateVisitCount() {
        logger.info("定时任务开始执行=======================");
        String updateSql=" update business_info set visit_count=0 ";
        try {
          jdbcTemplate.execute(updateSql);
            logger.info("定时任务执行完毕=======================");
        }catch (Exception e){
            logger.error("定时任务更新失败====================",e);
        }
    }


    /**
     * @description: 每天0点定时获取产品字典
     * @name ScheduledTasks
     * @author: xhj
     * @date: 2021/7/16
     * @version V1.0
     */
      @Scheduled(cron = "0 10 0 */1 * ?")
      public void getGoodsDict()   {
        jdbcTemplate.execute("delete from big_class_info");
        jdbcTemplate.execute("delete from small_class_info");
        jdbcTemplate.execute("delete from goods_select_info");
        logger.info("定时任务开始执行=======================");
        String result="";
        try{
            result = HttpUtils.doGet("https://zsl.sfood.zjamr.zj.gov.cn/app/zslOpenApi/goods/getThirdGoodsInfo", null);
            JSONObject jsonObj = JSONObject.parseObject(result);
            String data = jsonObj.get("data")+"";

            List<BigClassInfo> bigClassInfos= JSONObject.parseArray(data, BigClassInfo.class);
            //插入大类
            bigClassInfoImpl.saveBatch(bigClassInfos);
            for(BigClassInfo b:bigClassInfos){
                List<SmallClassInfo> smallClassInfos=b.getSmallClassInfo();
                for(SmallClassInfo s:smallClassInfos){
                    List<GoodsSelectInfo> goodsSelectInfos=s.getGoodsInfo();
                    goodsSelectInfos.forEach(e->e.setSmallClassCode(s.getSmallClassCode()));
                    s.setBigClassCode(b.getBigClassCode());
                    goodsSelectInfoImpl.saveBatch(goodsSelectInfos);
                }
                smallClassInfoImpl.saveBatch(smallClassInfos);
                smallClassInfos.forEach(e->e.setBigClassCode(b.getBigClassCode()));
                System.out.println(smallClassInfos);

            }


            logger.info("定时任务执行完毕=======================");


        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * @description: 浙农优品数据对接
     * @name ScheduledTasks
     * @author: xhj
     * @date: 2021/7/16
     * @version V1.0
     */
//    @Scheduled(cron = "0 */1 * * * ?")
//    @Scheduled(cron = "0 00 15 */1 * ?")
    public void getZnyp()   {

        logger.info("定时任务开始执行=======================");
        try{
            //先传分页参数page=1去查询一下总页数（傻逼接口）
            String result = HttpUtils.getZnyp("1");
            //获取总页数
            String recordCount = JSONObject.parseObject(JSONObject.parseObject(result).get("pages")+"").get("recordCount")+"";
            //循坏取数据一次只能取10条（大傻逼）
            int startPageCount = businessInfoMapper.selectZnypCount();//查询表中当前数量

            for(int i=1;i<=(Integer.valueOf(recordCount)-startPageCount)/10+1;i++){
                result = HttpUtils.getZnyp(i+"");
                String data=JSONObject.parseObject(result).get("data")+"";
                List<JSONObject> goods= JSONObject.parseArray(data,JSONObject.class);
                for(JSONObject obj:goods) {
                    //从上次页码开始取数有可能重复，所以用id进行判断
                    String id = obj.get("id") + "";
                    int count = businessInfoMapper.selectZnypRecord(id);
                    if (count == 0) {
                        businessInfoMapper.insertZnypRecord(id);
                        logger.info("id添加成功====================================================");

                        //主体信息
                        JSONObject ztxx = JSONObject.parseObject(obj.get("ztxx") + "");
                        BusinessInfo businessInfo = new BusinessInfo();
                        businessInfo.setCity(ztxx.get("area").toString().substring(5, 8));//傻逼接口提供的地市还要截取
                        businessInfo.setPhone(ztxx.get("lxrdh") + "");
                        businessInfo.setScale(ztxx.get("scgm") + "");
                        businessInfo.setUniscId(ztxx.get("zttyshxydm") + "");
                        businessInfo.setBusinessPersonName(ztxx.get("lxr") + "");
                        businessInfo.setBusinessName(ztxx.get("ztmc") + "");
                        businessInfo.setLeadingProduct(ztxx.get("zdcp") + "");
                        businessInfo.setProperty("331002");//接过来的数据全按农处理
                        businessInfo.setIsDelete(0);//默认0
                        businessInfo.setUpdateTime(LocalDateTime.now());
                        //重复的社会信用代码 不能重复插入
                        Map business = businessInfoMapper.selectCountByCode(ztxx.get("zttyshxydm") + "");
                        if (business == null) {
                            businessInfoMapper.insert(businessInfo);
                        } else {
                            businessInfo.setId(Integer.valueOf(business.get("id") + ""));
                        }
                        logger.info("主体信息添加成功====================================================");

                        //产品信息
                        JSONObject cpxx = JSONObject.parseObject(obj.get("cpxx") + "");
                        ProductInfo productInfo = new ProductInfo();
                        if("文旦".equals(cpxx.get("cpmc")+"")){
                            productInfo.setPName("柚");
                        }else{
                            productInfo.setPName(cpxx.get("cpmc")+"");
                        }
                        productInfo.setPickTime(TimeUtil.TimeConvert(cpxx.get("czrq") + ""));
                        productInfo.setWeight(cpxx.get("zsl") + "");
                        productInfo.setCreateTime(LocalDateTime.now());
                        productInfo.setLeadId(businessInfo.getId());
                        productInfo.setCreateTime(LocalDateTime.now());
                        productInfoMapper.insert(productInfo);
                        logger.info("产品信息添加成功====================================================");

                        //交易信息
                        JSONObject jyxx = JSONObject.parseObject(obj.get("jyxx") + "");
                        TradeInfo tradeInfo = new TradeInfo();
                        tradeInfo.setTradeName(jyxx.get("khmc") + "");
                        tradeInfo.setCode(jyxx.get("khtyshxydm") + "");
                        tradeInfo.setTradeTime(TimeUtil.TimeConvert(jyxx.get("jysj") + ""));
                        tradeInfo.setPInfoId(productInfo.getId());
                        tradeInfo.setCreateTime(LocalDateTime.now());
                        tradeInfoMapper.insert(tradeInfo);
                        logger.info("交易信息添加成功====================================================");

                        //定量监测信息
                        List<JSONObject> dljcxx = JSONObject.parseArray(obj.get("dljcxx") + "", JSONObject.class);
                        for (JSONObject dljc : dljcxx) {
                            DetectionInfo detectionInfo = new DetectionInfo();
                            detectionInfo.setUrl(dljc.get("jcbg") + "");
                            detectionInfo.setCreateTime(LocalDateTime.now());
                            detectionInfo.setPInfoId(productInfo.getId());
                            detectionInfo.setCreateTime(LocalDateTime.now());
                            detectionInfoMapper.insert(detectionInfo);

                        }
                        logger.info("定量监测信息添加成功====================================================");

                        //定性监测信息（快检）
                        List<JSONObject> dxjcxx = JSONObject.parseArray(obj.get("dxjcxx") + "", JSONObject.class);
                        for (JSONObject dxjc : dxjcxx) {
                            QuickScan quickScan = new QuickScan();
                            quickScan.setJcxm(dxjc.get("jcxm") + "");
                            quickScan.setJcdw(dxjc.get("jcdw") + "");
                            quickScan.setJcsj(dxjc.get("jcsj") + "");
                            quickScan.setJcjg(dxjc.get("jcjg") + "");
                            quickScan.setProductId(productInfo.getId() + "");
                            quickScan.setProperty("331002");
                            quickScanMapper.insert(quickScan);
                        }
                        logger.info("定性监测信息添加成功====================================================");

                        //种植信息
                        List<JSONObject> scgcxx = JSONObject.parseArray(obj.get("scgcxx") + "", JSONObject.class);
                        for (JSONObject scgc : scgcxx) {
                            OperateInfo operateInfo = new OperateInfo();
                            operateInfo.setOType(scgc.get("czlb") + "");
                            operateInfo.setInThing(scgc.get("trp") + "");
                            operateInfo.setOTime(TimeUtil.TimeConvert(scgc.get("czsj") + ""));
                            operateInfo.setPName(scgc.get("cpmc") + "");
                            operateInfo.setPInfoId(productInfo.getId());
                            operateInfo.setCreateTime(LocalDateTime.now());
                            operateInfoMapper.insert(operateInfo);
                        }
                        logger.info("种植信息添加成功====================================================");


                        //认证信息
                        List<JSONObject> rzxx = JSONObject.parseArray(obj.get("rzxx") + "", JSONObject.class);
                        for (JSONObject rz : rzxx) {
                            AuthenticationInfo authenticationInfo = new AuthenticationInfo();
                            authenticationInfo.setAuthType(rz.get("rzlb") + "");
                            authenticationInfo.setNumber(rz.get("zsbh") + "");
                            authenticationInfo.setYield(rz.get("pzcl") + "");
                            authenticationInfo.setProductName(rz.get("cpmc") + "");
                            authenticationInfo.setTermTime(TimeUtil.TimeConvert(rz.get("yxq") + ""));
                            authenticationInfo.setLeadId(businessInfo.getId());
                            authenticationInfo.setCreateTime(LocalDateTime.now());
                            authenticationInfoMapper.insert(authenticationInfo);
                        }
                        logger.info("认证信息添加成功====================================================");

                    }
                }

            }

            logger.info("定时任务执行完毕=======================");


        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * @description: 每天5点定时获取渔获物
     * @name ScheduledTasks
     * @author: xhj
     * @date: 2021/7/16
     * @version V1.0
     */
//    @Scheduled(cron = "0 40 11 */1 * ?")
    public void getYhw()   {
        String sql="select id from scjg_yhwsy_id";
        List<String> list=jdbcTemplate.queryForList(sql,String.class);
        logger.info("渔获物定时任务开始执行=======================");
        String url = "https://datashare.etz.gov.cn/gateway/api/677f7d51493b47e79159cffd4bd3b383/dataSharing/V37edXH1IoeC2d94.htm";
        HashMap param=new HashMap();
        param.put("appKey","A330000100000202105009512");
        long time=new Date().getTime();
        logger.info("时间戳===================================="+time);
        param.put("requestTime",time);
            String secret=getRequestSecret();
            JSONObject secretData = (JSONObject) JSON.parse(secret);
            JSONObject datas= secretData.getJSONObject("datas");
            String requestSecret=datas.getString("requestSecret");
            logger.info("获取到的密钥：{}",requestSecret);
        try {
            String sign=DigestUtils.md5DigestAsHex(("A330000100000202105009512"+requestSecret+time).getBytes("utf-8"));
            param.put("sign",sign);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        list.stream().forEach(e->{
            param.put("id",e);
            logger.info("渔获物接口参数：{}",JSONObject.toJSONString(param));
            try {
                String result = HttpUtils.doGet(url, param);
                if (result != null) {
                    logger.info("渔获物接口返回结果：{}", result);
                    JSONObject resultData = (JSONObject) JSON.parse(result);
                    JSONObject data1= resultData.getJSONObject("datas");
                    JSONArray array=data1.getJSONArray("data");
                    String lrmc= ((JSONObject) JSON.parse(array.get(0).toString())).getString("lrmc");
                    String dfmc= ((JSONObject) JSON.parse(array.get(0).toString())).getString("dfmc");
                    String zylx= ((JSONObject) JSON.parse(array.get(0).toString())).getString("zylx");
                    String yhzl= (((JSONObject) JSON.parse(array.get(0).toString())).getString("yhzl"));
                    String zyyq= (((JSONObject) JSON.parse(array.get(0).toString())).getString("zyyq"));
                    String yhsl= (((JSONObject) JSON.parse(array.get(0).toString())).getString("yhsl"));
                    String ggdw= (((JSONObject) JSON.parse(array.get(0).toString())).getString("ggdw"));
                    String yhgg= (((JSONObject) JSON.parse(array.get(0).toString())).getString("yhgg"));
                    String jylx= (((JSONObject) JSON.parse(array.get(0).toString())).getString("jylx"));
                    String xm= (((JSONObject) JSON.parse(array.get(0).toString())).getString("xm"));
                    String sagk= (((JSONObject) JSON.parse(array.get(0).toString())).getString("sagk"));
                    String yhmdd= (((JSONObject) JSON.parse(array.get(0).toString())).getString("yhmdd"));
                    String mddmc= (((JSONObject) JSON.parse(array.get(0).toString())).getString("mddmc"));
                    String blsj= (((JSONObject) JSON.parse(array.get(0).toString())).getString("blsj"));
                    String smsj= (((JSONObject) JSON.parse(array.get(0).toString())).getString("smsj"));
                    String createdate= (((JSONObject) JSON.parse(array.get(0).toString())).getString("createdate"));
                    String inSql="insert into BIZ_1000_YHWSY(LRMC,DFMC,ZYLX,YHZL,ZYYQ,YHSL,GGDW,YHGG,JYLX,XM,SAGK,YHMDD,MDDMC,BLSJ,SMSJ,CREATEDATE) values('"+lrmc+"','"+dfmc+"','"+zylx+"','"+yhzl+"'" +
                            ",'"+zyyq+"','"+yhsl+"','"+ggdw+"','"+yhgg+"','"+jylx+"','"+xm+"','"+sagk+"','"+yhmdd+"','"+mddmc+"','"+blsj+"','"+smsj+"','"+createdate+"')";
                    jdbcTemplate.execute(inSql);
                    logger.info("保存成功！！！");

                }
            }catch (Exception exc){
                logger.error("调用接口异常：{}",exc);

            }

        });
        logger.info("渔获物定时任务执行完毕=======================");

    }


    /**
     * @description: 每天5点定时获取船舶信息
     * @name ScheduledTasks
     * @author: xhj
     * @date: 2021/7/16
     * @version V1.0
     */
//    @Scheduled(cron = "0 00 12 */1 * ?")
    public void getBoat()   {
        String sql="select mobilename from scjg_mobile_mobilename";
        List<String> list=jdbcTemplate.queryForList(sql,String.class);
        logger.info("船舶定时任务开始执行=======================");
        String url = "https://datashare.etz.gov.cn/gateway/api/677f7d51493b47e79159cffd4bd3b383/dataSharing/a24923P7cq8lGad3.htm";
        HashMap param=new HashMap();
        param.put("appKey","A330000100000202105009512");
        long time=new Date().getTime();
        param.put("requestTime",time);
        String secret=getRequestSecret();
        JSONObject secretData = (JSONObject) JSON.parse(secret);
        JSONObject datas= secretData.getJSONObject("datas");
        String requestSecret=datas.getString("requestSecret");
        try {
            String sign=DigestUtils.md5DigestAsHex(("A330000100000202105009512"+requestSecret+time).getBytes("utf-8"));
            param.put("sign",sign);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        list.stream().forEach(e->{
            param.put("mobilename",e);
            logger.info("船舶接口参数：{}",JSONObject.toJSONString(param));
            try {
                String result = HttpUtils.doGet(url, param);
                if (result != null) {
                    logger.info("船舶接口返回结果：{}", result);
                    JSONObject resultData = (JSONObject) JSON.parse(result);
                    JSONObject data1= resultData.getJSONObject("datas");
                    JSONArray array=data1.getJSONArray("data");
                    String fiFisherhomeland= ((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherhomeland");
                    String mobilename= ((JSONObject) JSON.parse(array.get(0).toString())).getString("mobilename");
                    String fiFisherstuff= ((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherstuff");
                    String fiFishertype= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFishertype"));
                    String city= (((JSONObject) JSON.parse(array.get(0).toString())).getString("city"));
                    String country= (((JSONObject) JSON.parse(array.get(0).toString())).getString("country"));
                    String town= (((JSONObject) JSON.parse(array.get(0).toString())).getString("town"));
                    String village= (((JSONObject) JSON.parse(array.get(0).toString())).getString("village"));
                    String fiTasktype= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTasktype"));
                    String fiTasktrait= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTasktrait"));
                    String mmsi= (((JSONObject) JSON.parse(array.get(0).toString())).getString("mmsi"));
                    String fiTotallength= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTotallength"));
                    String fiFisherlength= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherlength"));
                    String fiFisherwidth= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherwidth"));
                    String fiFisherdepth= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherdepth"));
                    String fiTotalton= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTotalton"));
                    String fiMineton= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiMineton"));
                    String fiMainpower= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiMainpower"));
                    String fiRadio= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiRadio"));
                    String fiAirdoor= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiAirdoor"));
                    String fiOwnerphone= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiOwnerphone"));
                    String fiOwnermobile= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiOwnermobile"));
                    String fiTestnum= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTestnum"));
                    String satellitePhone= (((JSONObject) JSON.parse(array.get(0).toString())).getString("satellitePhone"));
                    String terminalId= (((JSONObject) JSON.parse(array.get(0).toString())).getString("terminalId"));
                    String terminalType= (((JSONObject) JSON.parse(array.get(0).toString())).getString("terminalType"));
                    String terminalCode= (((JSONObject) JSON.parse(array.get(0).toString())).getString("terminalCode"));
                    String inSql="insert into BIZ_1000_MOBILE_TZ(FI_FISHERHOMELAND,MOBILENAME,FI_FISHERSTUFF,FI_FISHERTYPE,CITY,COUNTRY,TOWN,VILLAGE,FI_TASKTYPE,FI_TASKTRAIT,MMSI,FI_TOTALLENGTH,FI_FISHERLENGTH,FI_FISHERWIDTH,FI_FISHERDEPTH,FI_TOTALTON,FI_MINETON,FI_MAINPOWER,FI_RADIO,FI_AIRDOOR,FI_OWNERPHONE,FI_OWNERMOBILE,FI_TESTNUM,SATELLITE_PHONE,TERMINAL_ID,TERMINAL_TYPE,TERMINAL_CODE) " +
                            "values('"+fiFisherhomeland+"','"+mobilename+"','"+fiFisherstuff+"','"+fiFishertype+"'" +
                            ",'"+city+"','"+country+"','"+town+"','"+village+"','"+fiTasktype+"','"+fiTasktrait+"','"+mmsi+"','"+fiTotallength+"','"+fiFisherlength+"','"+fiFisherwidth+"','"+fiFisherdepth+"','"+fiTotalton+"','"+fiMineton+"','"+fiMainpower+"','"+fiRadio+"','"+fiAirdoor+"','"+fiOwnerphone+"','"+fiOwnermobile+"','"+fiTestnum+"','"+satellitePhone+"','"+terminalId+"','"+terminalType+"','"+terminalCode+"')";
                    jdbcTemplate.execute(inSql);
                    logger.info("保存成功！！！");
                }
            }catch (Exception exc) {
                logger.error("调用接口异常：{}", exc);
            }

        });
        logger.info("船舶定时任务执行完毕=======================");

    }

    public static String getRequestSecret() {
        String url = "https://datashare.etz.gov.cn/gateway/app/refreshTokenByKey.htm";
        HashMap param=new HashMap();
        param.put("appKey","A330000100000202105009512");
        long time=new Date().getTime();
        param.put("requestTime",time);
        try {
            String sign=DigestUtils.md5DigestAsHex(("A330000100000202105009512"+"287a061be0274c1b92f902ed946b21c1"+time).getBytes("utf-8"));
            param.put("sign",sign);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            String result = HttpUtils.doGet(url, param);
            if (result != null) {
                logger.info("获取RequestSecret接口返回结果：{}", result);
                return result;
            }
        }catch (Exception exc){
            logger.error("调用获取RequestSecret接口异常：{}",exc);
        }
        return  null;

    }

    public static void main(String[] args) {
      String  str="{\"code\":\"00\",\"msg\":\"成功\",\n" +
              "\"datas\":\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\",\\\"data\\\":[{\\\"country\\\":\\\"玉环\\\",\\\"fiAirdoor\\\":\\\"0\\\",\\\"fiTaskmode\\\":\\\"8\\\",\\\"city\\\":\\\"台州市\\\",\\\"mmsi\\\n" +
              "\":\\\"412415107\\\",\\\"fiOwnermobile\\\":\\\"13600579813\\\",\\\"fiTasktrait\\\":\\\"0\\\",\\\"satellitePhone\\\":\\\"-\\\",\\\"fiFisherhomeland\\\":\\\"-\\\",\\\"terminalId\\\":\\\"5333\n" +
              "9181\\\",\\\"mobilename\\\":\\\"浙玉渔11889\\\",\\\"fiMainpower\\\":\\\"11.8\\\",\\\"fiTotallength\\\":\\\"-\\\",\\\"deleteFlag\\\":\\\"0\\\",\\\"fiFisherwidth\\\":\\\"2.8\\\",\\\"fiFishers\n" +
              "tuff\\\":\\\"2\\\",\\\"fiMineton\\\":\\\"-\\\",\\\"fiFisherdepth\\\":\\\"1.08\\\",\\\"village\\\":\\\"民主\\\",\\\"fiRadio\\\":\\\"0\\\",\\\"fiFishertype\\\":\\\"1\\\",\\\"town\\\":\\\"坎门\\\",\\\"fiT\n" +
              "asktype\\\":\\\"3\\\",\\\"terminalType\\\":\\\"16\\\",\\\"fiTotalton\\\":\\\"9.0\\\",\\\"mobileId\\\":\\\"10052288\\\",\\\"fiOwnerphone\\\":\\\"13600579813\\\",\\\"terminalCode\\\":\\\"AD32 \n" +
              "76\\\",\\\"fiFisherlength\\\":\\\"11.8\\\",\\\"fiTestnum\\\":\\\"3310220210037\\\"}],\\\"traceId\\\":\\\"10.49.170.252_18090-acc2f1f518bb086d\\\"}\",\"dataCount\":1,\"requestI \n" +
              "d\":\"d3b83be18a254506b2df292a131e78a3\"}";
        JSONObject secretData = (JSONObject) JSON.parse(str);
        JSONObject datas= secretData.getJSONObject("datas");
        JSONArray array=datas.getJSONArray("data");
        String fiFisherhomeland= ((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherhomeland");
        String mobilename= ((JSONObject) JSON.parse(array.get(0).toString())).getString("mobilename");
        String fiFisherstuff= ((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherstuff");
        String fiFishertype= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFishertype"));
        String city= (((JSONObject) JSON.parse(array.get(0).toString())).getString("city"));
        String country= (((JSONObject) JSON.parse(array.get(0).toString())).getString("country"));
        String town= (((JSONObject) JSON.parse(array.get(0).toString())).getString("town"));
        String village= (((JSONObject) JSON.parse(array.get(0).toString())).getString("village"));
        String fiTasktype= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTasktype"));
        String fiTasktrait= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTasktrait"));
        String mmsi= (((JSONObject) JSON.parse(array.get(0).toString())).getString("mmsi"));
        String fiTotallength= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTotallength"));
        String fiFisherlength= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherlength"));
        String fiFisherwidth= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherwidth"));
        String fiFisherdepth= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiFisherdepth"));
        String fiTotalton= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTotalton"));
        String fiMineton= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiMineton"));
        String fiMainpower= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiMainpower"));
        String fiRadio= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiRadio"));
        String fiAirdoor= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiAirdoor"));
        String fiOwnerphone= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiOwnerphone"));
        String fiOwnermobile= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiOwnermobile"));
        String fiTestnum= (((JSONObject) JSON.parse(array.get(0).toString())).getString("fiTestnum"));
        String satellitePhone= (((JSONObject) JSON.parse(array.get(0).toString())).getString("satellitePhone"));
        String terminalId= (((JSONObject) JSON.parse(array.get(0).toString())).getString("terminalId"));
        String terminalType= (((JSONObject) JSON.parse(array.get(0).toString())).getString("terminalType"));
        String terminalCode= (((JSONObject) JSON.parse(array.get(0).toString())).getString("terminalCode"));
        String inSql="insert into BIZ_1000_MOBILE_TZ(FI_FISHERHOMELAND,MOBILENAME,FI_FISHERSTUFF,FI_FISHERTYPE,CITY,COUNTRY,TOWN,VILLAGE,FI_TASKTYPE,FI_TASKTRAIT,MMSI,FI_TOTALLENGTH,FI_FISHERLENGTH,FI_FISHERWIDTH,FI_FISHERDEPTH,FI_TOTALTON,FI_MINETON,FI_MAINPOWER,FI_RADIO,FI_AIRDOOR,FI_OWNERPHONE,FI_OWNERMOBILE,FI_TESTNUM,SATELLITE_PHONE,TERMINAL_ID,TERMINAL_TYPE,TERMINAL_CODE) " +
                "values('"+fiFisherhomeland+"','"+mobilename+"','"+fiFisherstuff+"','"+fiFishertype+"'" +
                ",'"+city+"','"+country+"','"+town+"','"+village+"','"+fiTasktype+"','"+fiTasktrait+"','"+mmsi+"','"+fiTotallength+"','"+fiFisherlength+"','"+fiFisherwidth+"','"+fiFisherdepth+"','"+fiTotalton+"','"+fiMineton+"','"+fiMainpower+"','"+fiRadio+"','"+fiAirdoor+"','"+fiOwnerphone+"','"+fiOwnermobile+"','"+fiTestnum+"','"+satellitePhone+"','"+terminalId+"','"+terminalType+"','"+terminalCode+"')";
        System.out.println(inSql);
    }
}



